﻿$(".kj_wsjhhaa").click(
    function () {
        $(this).parent().addClass("active");
        $(this).next().next().show();
        $(this).hide();
        $(this).next().show();
      
       
    }
);
$(".kj_wsjhahh").click(function () {
    $(this).next().show();
    $(this).hide();
    $(this).prev().show();
    $(this).parent().removeClass("active");
});
//$(".kj_prolist>li>img").click(function () {
//    $(this).next().show();
//},
//    function () {
//        $(this).next().hide();
//    }
//);

$(".kj-help-ul a").each(function () {
    var localurl = location.href;
    var url = $(this).attr("href");
    if (localurl.indexOf(url) != -1) {
        $(this).parent().addClass("active");
    }
});
$(".kj_returntop").click(function () {
    $("html,body").animate({
        'scrollTop': '0px'
    }, 300)
});
$(".list-group li a").each(function () {
    var localurl = location.href;
    var url = $(this).attr("href");
    if (localurl.indexOf(url) != -1) {
        $(this).parent().addClass("active");

    }
});

$(".kj_qtnav>ul>li>a").each(function () {
    var localurl = location.href;
    var url = $(this).attr("href");
    if (localurl.indexOf(url) != -1) {
        $(this).parent().addClass("active");

    }
});
$(".kj_qtnav>ul>li:first-child").removeClass("active");

$(".sub_dt.active").parent().parent().parent().addClass("active");


$(".kj-slide-right-bar2").hover(function () {
    $(".kj-slide-right-bar2").css("right", "5px");
    $(".kj-slide-right-bar2 .email").css('height', '155px');
    $(".kj-slide-right-bar2 .qq").css('height', '200px');
    $(".kj-slide-right-bar2").css('top', '50px');

}, function () {
    $(".kj-slide-right-bar2").css("right", "-165px");
    $(".kj-slide-right-bar2 li").css('height', '40px');
    $(".kj-slide-right-bar2").css('top', '50px');

});


(function ($) {
    $.extend({
        urlGet: function () {
            var aQuery = window.location.href.split("?");  //取得Get参数
            var aGET = new Array();
            if (aQuery.length > 1) {
                var aBuf = aQuery[1].split("&");
                for (var i = 0, iLoop = aBuf.length; i < iLoop; i++) {
                    var aTmp = aBuf[i].split("=");  //分离key与Value
                    aGET[aTmp[0]] = aTmp[1];
                }
            }
            return aGET;
        }
    })
})(jQuery);
var isTouch = ('ontouchstart' in window);
var BodyPading = { top: 0, bottom: 50 ,viewmode:"xs"};
var ShowShopConfig = {
    defaultcss: false,
    aftershopcartfill: function (o) {
        if (o.length == 0) {
            $(".kj-shopcart-count").html(o.length).hide();
        }
        else {
            $(".kj-shopcart-count").html(o.length).show();
        }

    },
    afteraddtocart: function (o) {
        if (o != null) {
            var of = $(o).offset();
        
            var cof = $(".kj-shopcart-count[atom='1']").show().offset();
            
            var gift = $('<div style="position:absolute;left:' + of.left + 'px;top:' + of.top + 'px"><i class="fa fa-gift fa-3x" style="color:#ff6600;"></i></div>')
            $("body").append(gift);
            gift.animate({ left: cof.left + "px", top: cof.top + "px", opacity: 0 }, 1000, function () {
                gift.remove();
            })
        }
    },
    viewminshopcartbox: function (o) {
        //  var offset = $(o).offset();
        //  $("#ShopCartBox").css({ left: offset.left - ($("#ShopCartBox").width() - $(o).outerWidth()) + "px", top: offset.top + $(o).outerHeight() + "px" }).toggle();
    }
};
function UserLoginByAjax(el, callback) {
    VerifyFormData({ el: el }, function (postdata, extdata) {

        postdata = $.extend(postdata, { a: 'ajaxuserlogin' });
        $("input[role='userloginbtn']").val(rclng.loading).attr("disabled", true);

        $.post(webhttp + "index.aspx", postdata,
           function (data, textStatus) {
               rv = data;
               if (rv.Status == "1") {
                   if (callback != undefined) {
                       callback(rv.StrResult);
                   }
                   else {
                       location.href = rv.StrResult;
                   }
               }
               else {
                   $("input[role='userloginbtn']").val(rclng.login).attr("disabled", false);
                   $(".userlogin_verifycodedl").show();
                   alert(rv.ClientMsg);
               }
           }, "json");

    });
}
function initResponseView2() {
    /**通用-banner大图自定义缩放**/
    var zoomWidth = 992; //缩放阀值992px, 即所有小于992px的视口都会对原图进行缩放, 只是缩放比例不同
    var maxWidth = 1920; //最大宽度1920px
    var ratio = 1; //缩放比例
    var viewWidth = window.innerWidth; // 视口宽度
    var zoomSlider = function () {
        if (viewWidth < 768) { //当视口小于768时(移动端), 按992比例缩放
            ratio = viewWidth / zoomWidth; //视口宽度除以阀值, 计算缩放比例
            $("body").css({ "padding-top": BodyPading.top + "px", "padding-bottom": BodyPading.bottom + "px" });
            $(".pagination").removeClass("pagination-lg").addClass("pagination-md");
            $(".kj-shopcart-suminfo-box .btn").addClass("btn-sm");
        } else if (viewWidth < zoomWidth) { //当视口界于768与992之间时, bootstrap主宽度为750, 这区间图片缩放比例固定.
            ratio = zoomWidth / (zoomWidth + (zoomWidth - 750));
            $("body").css({ "padding-top": BodyPading.top + "px", "padding-bottom": BodyPading.bottom + "px" });
            $(".pagination").removeClass("pagination-md").addClass("pagination-lg");
            $(".kj-shopcart-suminfo-box .btn").removeClass("btn-sm");
        } else { // PC端不缩放
            ratio = 1;
            $(".pagination").removeClass("pagination-md").addClass("pagination-lg");
            $(".kj-shopcart-suminfo-box .btn").removeClass("btn-sm");
            $("body").css({ "padding-top": "0px", "padding-bottom": "0px" });
        }
        //ratio = viewWidth / zoomWidth; //视口宽度除以阀值, 计算缩放比例
        //ratio = (ratio<=1) ? ratio : 1; //如果比例值大于1, 说明视口宽度高于阀值, 则不进行任何缩放
        var width = maxWidth * ratio; //缩放宽度
        $(".my-slide img").each(function () {
            $(this).css({
                "width": width,
                "max-width": width,
                "margin-left": -(width - viewWidth) / 2
            }); //图片自适应居中, 图片宽度与视口宽度差除以2的值, 设置为负margin
        });
    }


    zoomSlider(); //页面加载时初始化并检查一次.

    /**视口发生变化时的事件**/
    $(window).resize(function () {
        viewWidth = window.innerWidth; // 重置视口宽度
        zoomSlider();//判断是否绽放banner

    });
}
function initResponseView() {
    /**通用-banner大图自定义缩放**/
    var zoomWidth = 992; //缩放阀值992px, 即所有小于992px的视口都会对原图进行缩放, 只是缩放比例不同
    var maxWidth = 1920; //最大宽度1920px
    var ratio = 1; //缩放比例
    var viewWidth = window.innerWidth; // 视口宽度
   
    var zoomSlider = function () {
        var bannerheight = 420;
        $("body").css({ "padding-top": "0px", "padding-bottom": "0px" });

        if (viewWidth >= 768 && viewWidth <= zoomWidth) { //当视口界于768与992之间时, bootstrap主宽度为750, 这区间图片缩放比例固定.
            ratio = zoomWidth / (zoomWidth + (zoomWidth - 750));
            if (BodyPading.viewmode == "sm") {
                $("body").css({ "padding-top": BodyPading.top + "px", "padding-bottom": BodyPading.bottom + "px" });
            }
            $(".pagination").removeClass("pagination-md").addClass("pagination-lg");
            $(".kj-shopcart-suminfo-box .btn").removeClass("btn-sm");
        }
        else if (viewWidth < 768) { //当视口小于768时(移动端), 按992比例缩放
            ratio = viewWidth / zoomWidth; //视口宽度除以阀值, 计算缩放比例
            bannerheight = 200;
            $("body").css({ "padding-top": BodyPading.top + "px", "padding-bottom": BodyPading.bottom + "px" });
            $(".pagination").removeClass("pagination-lg").addClass("pagination-md");
            $(".kj-shopcart-suminfo-box .btn").addClass("btn-sm");
        }  else { // PC端不缩放
            ratio = 1;
            $(".pagination").removeClass("pagination-md").addClass("pagination-lg");
            $(".kj-shopcart-suminfo-box .btn").removeClass("btn-sm");
        }
        //ratio = viewWidth / zoomWidth; //视口宽度除以阀值, 计算缩放比例
        //ratio = (ratio<=1) ? ratio : 1; //如果比例值大于1, 说明视口宽度高于阀值, 则不进行任何缩放
        var width = maxWidth * ratio; //缩放宽度
        $(".my-slide .item a").height(bannerheight);
        //$(".my-slide img").each(function () {
        //    $(this).css({
        //        "width": width,
        //        "max-width": width,
        //        "margin-left": -(width - viewWidth) / 2
        //    }); //图片自适应居中, 图片宽度与视口宽度差除以2的值, 设置为负margin
        //});
    }

    zoomSlider(); //页面加载时初始化并检查一次.

    /**视口发生变化时的事件**/
    $(window).resize(function () {
        viewWidth = window.innerWidth; // 重置视口宽度
        zoomSlider();//判断是否绽放banner

    });
    var topmainheight = $("#topmainbox").height();
    $(".kj-topmain-col").height(topmainheight);
}
function initCarouselTouch() {

    if (isTouch) {
        $(".carousel").on('touchstart', function (e) {
            var that = $(this);
            var touch = e.originalEvent.changedTouches[0];
            var startX = touch.pageX;
            var startY = touch.pageY;
            $(document).on('touchmove', function (e) {
                touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
                var endX = touch.pageX - startX;
                var endY = touch.pageY - startY;
                if (Math.abs(endY) < Math.abs(endX)) {
                    if (endX > 10) {
                        $(this).off('touchmove');
                        that.carousel('prev');
                    } else if (endX < -10) {
                        $(this).off('touchmove');
                        that.carousel('next');
                    }
                    return false;
                }
            });
        });
        $(document).on('touchend', function () {
            $(this).off('touchmove');
        });
    }
}

function initscroll() {
    if ($("#kjtopsearchbox").length > 0) {
        $(window).scroll(function () {
            var viewWidth = window.innerWidth; // 视口宽度
            if (viewWidth >= 768) {
                var wt = $(window).scrollTop();

                if (wt > 250) {
                    $("#kjtopsearchbox").css({
                        "position": "fixed",
                        "left": "0px",
                        "right": "0px",
                        "top": "0px",
                        "z-index": "99999",
                        "box-shadow": "0px 5px 5px rgba(0,0,0,.1)"
                    });
                    $(".kj-mainarea,.kj-user-border-main").addClass("kj-mar215");
                    $(".kj-topsearch-in").css("min-height", "85px");
                    $(".kj-topsearch-tool").hide();
                    $("#kj-topsearch-row").css("padding-top", "20px");
                }
                else {
                    $("#kjtopsearchbox").css({
                        "position": "initial",
                        "left": "initial",
                        "right": "initial",
                        "top": "initial",
                        "z-index": "initial",
                        "box-shadow": "none"
                    });
                    $(".kj-mainarea,.kj-user-border-main").removeClass("kj-mar215");
                    $(".kj-topsearch-in").css("min-height", "195px");
                    $(".kj-topsearch-tool").show();
                    $("#kj-topsearch-row").css("padding-top", "50px");
                }
            }
            else {
                $("#kjtopsearchbox").css({
                    "position": "initial",
                    "left": "initial",
                    "right": "initial",
                    "top": "initial",
                    "z-index": "initial",
                    "box-shadow": "none"
                });
                $(".kj-mainarea,.kj-user-border-main").removeClass("kj-mar215");
                $(".kj-topsearch-in").css("min-height", "195px");
                $(".kj-topsearch-tool").show();
                $("#kj-topsearch-row").css("padding-top", "50px");
            }
        });
    }
}
$(function () {

    initResponseView();//响应式
    initCarouselTouch();//图片轮播触屏
    initscroll();//固定导航条
    InitUserLoginStatus({
        el: "#loginstatusbox", ondone: function (data) {
            if (data.result == "1") {
                $(".kc_user_head_logo").attr("src", data.headlogo);
                $("#homeloginstatus").html('<h4 class="media-heading">'+data.username+'</h4>\
                                <div><i class="fa fa-user"></i> '+data.rolename+'</div>');
                $("#ineuserstausboxx").html('<a href="' + data.usercenter + '" id="ucenterurlhref">Member Center</a>&nbsp;&nbsp;|&nbsp;&nbsp; <a href="' + data.loginouturl + '">Sign Out</a> ');
                NowUserInfo = data;
                GetShopChatCountForNowUser({
                    callback: function (data) {
                        if (data.result == "1") {
                            if (data.data.count == "0" || data.data.count == "") {
                                $(".kj-shopcart-count").html(data.data.count).hide();
                            }
                            else {

                                $(".kj-shopcart-count").html(data.data.count).show();
                            }
                        }
                    }
                })
            }
            else if (data.result == "-1") {
                $(".kj-shopcart-count").html("0").hide();
                $("#loginstatusbox").html('<a href="' + data.loginurl + '">请登录</a><a href="' + data.regurl + '">注册</a>');
                $("#homeloginstatus").html('<a href="' + data.loginurl + '">请登录</a><a href="' + data.regurl + '">注册</a>');
            }
        }
    });
    var turl = location.href;
    turl = turl.replace("//", "");
    turl = turl.substr(turl.indexOf("/"));
    $(".list-group-item > a[href*='" + turl + "']").parent().addClass("active");
});